﻿using MediatR;
using W.Warehouse.Api.Application.Command.OutboundCommand;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.OutboundCommandHadler
{
    public class OutboundIsdelAllCommandHandler : IRequestHandler<OutboundIsdelAllCommand, int>
    {
        private readonly IOutboundRepository outboundRepository;

        public OutboundIsdelAllCommandHandler(IOutboundRepository outboundRepository)
        {
            this.outboundRepository = outboundRepository;
        }

        public async Task<int> Handle(OutboundIsdelAllCommand request, CancellationToken cancellationToken)
        {
            var list = (await outboundRepository.GetAllAsync()).Where(w => request.ints.Contains(w.Outboundid)).ToList();
            list.ForEach(w =>
            {
                w.IsDelete = true;
                w.DeleteTime = DateTime.Now;
            });
            return await outboundRepository.UpdateRangeAsync(list);
        }
    }
}
